package cn.yuyin.utile;

import java.io.IOException;
import java.util.Random;

import javax.microedition.lcdui.Image;

public class ShopImg {
	
	private static Image[] imgArr = new Image[10] ;
	private static Image error  ;
	
	private static int imgInd =0 ;
	//private static Random random  = new Random();
//	private int intRdm = random.nextInt(10) ;

	
//	public static Image getImg()
//	{
//		
//		int intRdm = random.nextInt(10) ;
//		if(imgArr[intRdm]!=null)
//		{
//			return imgArr[intRdm] ;
//		}
//		else
//		{
//			try {
//				imgArr[intRdm] = Image.createImage("/canyin"+intRdm+".png") ;
//				
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			return imgArr[intRdm] ;
//		}
//		
//	}
	
	public static Image getImg()
	{
		
		//System.out.println("index = ==="+ShopImg);
		if(imgArr[ShopImg.imgInd]!=null)
		{
			return imgArr[ShopImg.imgInd] ;
		}
		else
		{
			try {
				imgArr[ShopImg.imgInd] = Image.createImage("/canyin"+ShopImg.imgInd+".png") ;
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return imgArr[ShopImg.imgInd] ;
		}
	
	}
	public static int getImgInd() {
		return imgInd;
	}
	public static void setImgInd(int imgInd) {
		ShopImg.imgInd = imgInd;
	}
	public static Image getImg(int index)
	{
		
		if(index==-1)
		{
			if(error!=null)
			{
				return error ;
			}
			else
			{
				try {
					error = Image.createImage("/error.png") ;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return error ;
			}
			
		}
		
		System.out.println("index = ==="+index);
		if(imgArr[index]!=null)
		{
			return imgArr[index] ;
		}
		else
		{
			try {
				imgArr[index] = Image.createImage("/canyin"+index+".png") ;
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return imgArr[index] ;
		}
	
	}

}
